﻿'********************************************************************************
'*
'*      組立ロット詳細情報画面
'*
'*      File Name : frmBakeLotStateCheck.vb
'*      Title     : 組立ロット詳細情報画面（ベーク）
'*      機能    　：ラックNoを入力する
'*
'********************************************************************************
'----------------------------------<<修正履歴>>----------------------------------
'ﾊﾞｰｼﾞｮﾝ   日付       作業者        ｺﾒﾝﾄ
'--------- ---------- ------------ -----------------------------------------------
' V1.0.0   2017/06/30 F.Gotou   新規作成
'********************************************************************************

Imports System.Text
Public Class frmBakeLotStateCheck
    'ベーク画面
    Private frmBake As Object

    'クリックされたボタン名
    Public btnName As String

    '配列番号
    Dim idx As Integer

    '一貫ラックNoの文字列
    Dim rackNoStr = ""

    '装置ID
    Dim lotEquipId As String

    '工程コード
    Dim lotProcCd As String

    '不良数関連の定数
    Protected m_cLotDefect As New clsDbLotDefect
    Protected dtError As New DataTable
    Public TotalCount As Integer = 0

    Public Sub New(ByVal fr As Object)

        MyBase.New()
        frmBake = fr
        InitializeComponent()

    End Sub

    'フォームロード時
    Private Sub frmBakeLotStateCheck_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'ボタン名から配列番号を取得
        idx = CInt(btnName.Substring(12)) - 1

        '組立ロットNo
        txtLotNo.Text = frmBake.dtAllLot.Rows(idx)("LOT_NO")

        '拡散ロットNO
        txtDiffLot.Text = frmBake.dtAllLot.Rows(idx)("WAFERLOT_NO")

        '装置ID

        lotEquipId = frmBake.dtAllLot.Rows(idx)("EQP_NO")

        '工程コード
        lotProcCd = frmBake.dtAllLot.Rows(idx)("PROCESS_CD")

        '一貫ラックNo
        txtConsRackNo.Text = frmBake.dtAllLot.Rows(idx)("CONS_RACK_NO")

        '品名
        txtProdName.Text = frmBake.dtAllLot.Rows(idx)("PROD_NAME")

        '製品外形
        txtShape.Text = frmBake.dtAllLot.Rows(idx)("SHAPE")

        'X線検査方式
        If txtXrayCheckSpec.Visible = True Then
            If Not IsDBNull(frmBake.dtAllLot.Rows(idx)("XRAY_CHECK_SPEC")) Then
                txtXrayCheckSpec.Text = frmBake.dtAllLot.Rows(idx)("XRAY_CHECK_SPEC")
            End If
        End If

        '前工程完成数
        txtPreCompleteQty.Text = frmBake.dtAllLot.Rows(idx)("PRE_COMPLETE_NUM")

        '基板・フレーム枚数
        txtPreFrameQty.Text = frmBake.dtAllLot.Rows(idx)("SUB_FRAME_NUM")

        '結果
        If Not IsDBNull(frmBake.dtAllLot.Rows(idx)("RESULT")) Then
            txtResult.Text = frmBake.dtAllLot.Rows(idx)("RESULT")
        End If

        If frmBake.dtAllLot.Rows(idx)("LOT_STATE") = frmStartCompleteBase.TagProcessStatus.Ready Then
            '完成数
            txtCompCnt.Text = "0"
            '枚数
            txtPcbNum.Text = "0"
            '不良数
            txtLotFailCnt.Text = "0"

        Else
            '完成数
            txtCompCnt.Text = frmBake.dtAllLot.Rows(idx)("COMPLETE_NUM")
            '枚数
            txtPcbNum.Text = frmBake.dtAllLot.Rows(idx)("FRAME_NUM")
            '不良数
            txtLotFailCnt.Text = frmBake.dtAllLot.Rows(idx)("FAILD_NUM")

        End If

        If frmBake.dtAllLot.Rows(idx)("LOT_STATE") = frmStartCompleteBase.TagProcessStatus.Processing Then
            'クリアボタン
            btnClear.Enabled = False
            '枚数
            btnPcbNum.Enabled = True
            '不良数
            btnFailCnt.Enabled = True
        Else
            btnClear.Enabled = True
        End If

        'イベント設定

        '枚数
        AddHandler btnPcbNum.Click, AddressOf tkl_Click
        AddHandler txtPcbNum.MouseHover, AddressOf MouseOverColor
        AddHandler txtPcbNum.MouseMove, AddressOf MouseOverColor

    End Sub

    'OKボタン押下時
    Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click

        If Not frmBake.dtAllLot.Rows(idx)("LOT_STATE") = frmStartCompleteBase.TagProcessStatus.Ready Then
            frmBake.dtAllLot.Rows(idx)("COMPLETE_NUM") = txtCompCnt.Text
            frmBake.dtAllLot.Rows(idx)("FRAME_NUM") = txtPcbNum.Text
            frmBake.dtAllLot.Rows(idx)("FAILD_NUM") = txtLotFailCnt.Text
        End If

        '製造完成フラグは計上完成
        frmBake.dtAllLot.Rows(idx)("COMP_TYPE") = "3"

        Me.Close()
    End Sub

    'CLEARボタン押下時
    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
        '初期化
        For i As Integer = 0 To frmBake.dtAllLot.Columns.Count - 1
            If TypeOf frmBake.dtAllLot.Rows(idx)(i) Is Integer Then
                frmBake.dtAllLot.Rows(idx)(i) = 0
            Else
                frmBake.dtAllLot.Rows(idx)(i) = String.Empty
            End If
        Next

        Dim BtnLot As Control() = frmBake.Controls.Find(btnName, True)
        If BtnLot.Length > 0 Then
            CType(BtnLot(0), Button).Text = frmBake.getMsgStr("MSG00051")
            CType(BtnLot(0), Button).Enabled = False
        End If
        Me.Close()
    End Sub

    '不良数ボタン押下時
    Private Sub btnFailCnt_Click(sender As Object, e As EventArgs) Handles btnFailCnt.Click
        Dim frmErrInput As New frmLotCategoryInput
        frmErrInput.LotNo = txtLotNo.Text
        frmErrInput.EquipID = g_EQUIP_NO 'g_CURRENT_EQUIP_ID 'UPD 苗 2018/1/19 装置No.の対応
        frmErrInput.KouteiCD = lotProcCd
        frmErrInput.StartPosition = FormStartPosition.CenterScreen
        frmErrInput.preProcCompleteCnt = CInt(txtPreCompleteQty.Text)
        frmErrInput.ShowDialog()

        Dim compCnt As Integer = Integer.Parse(txtPreCompleteQty.Text) - frmErrInput.FailCount

        If compCnt >= 0 Then
            txtCompCnt.Text = compCnt.ToString()
            txtLotFailCnt.Text = frmErrInput.FailCount
        End If

    End Sub


    Overridable Sub tkl_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim clickBtn As Button = CType(sender, Button)
        Dim lblInputPos As Label = clickBtn.Parent.Controls.Find(String.Format("txt{0}", clickBtn.Name.Substring(3)), False)(0)

        GetControlItem(Me, lblInputPos)

        Dim pt2Screen As Point = lblInputPos.PointToScreen(New Point(0, -15))
        modTenkey.CallTenkey(lblInputPos, Me, AddressOf TenkeyInputCompleted,
                             pt2Screen.X - Me.Left, pt2Screen.Y - Me.Top)
    End Sub

    Overridable Sub TenkeyInputCompleted()

    End Sub

    Private Sub GetControlItem(Ctrl As Control, ByVal sender As System.Object)
        For Each CtrlItem As Control In Ctrl.Controls
            If TypeOf CtrlItem Is TenKey Then
                CtrlItem.Dispose()
            End If
            If TypeOf CtrlItem Is TenKey Then
                CtrlItem.Dispose()
            End If
            If CtrlItem IsNot sender Then
                If TypeOf CtrlItem Is TenKeyLabel Then
                    CType(CtrlItem, TenKeyLabel).EndEdit()

                ElseIf TypeOf CtrlItem Is Label Then
                    If CtrlItem.BackColor = Color.Cyan Then
                        CtrlItem.BackColor = frmStartCompleteBase.TENKEY_INIT_COLOR
                    End If
                End If
            End If
            If CtrlItem.Controls.Count > 0 Then
                GetControlItem(CtrlItem, sender)
            End If
        Next
    End Sub

    Private Sub MouseOverColor(ByVal sender As Object, ByVal e As EventArgs)
        sender.BackColor = frmStartCompleteBase.NORMAL_INIT_COLOR
    End Sub

End Class